﻿
@{
    ViewBag.Title = "会员特权列表";
}
@section CSS{

}
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            会员特权
            <small>列表</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="#">系统管理</a></li>
            <li class="active">会员特权列表</li>
        </ol>
    </section>
    <section>
        <div class="col-xs-12">
            <div class="box box-primary ">
                <!-- form start -->
                <form class="form-horizontal">
                    <div class="box-body">
                        <div class="form-group">
                            <label for="name" class="col-sm-2 control-label">特权名称</label>
                            <div class="col-sm-2">
                                <input type="text" class="form-control" id="name" placeholder="特权名称">
                            </div>
                            <label for="classSelect" class="col-sm-2 control-label">状态</label>
                            <div class="col-sm-2">
                                <select class="form-control" id="classSelect">
                                    <option value="-1">-请选择状态-</option>
                                    <option value="1">开启</option>
                                    <option value="0">禁用</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer ">
                        <button type="button" class="btn btn-primary btn-search center-block" id="btnSearch"><i class="fa fa-search"></i> 查询</button>
                        @*<button type="button" class="btn btn-danger" id="btnDelMul"><i class="fa fa-remove"></i> 批量删除</button>*@
                        <button type="button" class="btn btn-info" id="btnAdd" onclick="window.location.href = '/systemsetting/AddUserRule'"><i class="fa fa-plus"></i> 添加</button>
                        @*<button type="button" class="btn btn-success" id="btnExport"><i class="fa fa-download"></i> 导出Excel</button>*@
                    </div>
                    <!-- /.box-footer -->
                </form>
            </div>
        </div>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    @*<div class="box-header">
                            &nbsp;
                        </div>*@
                    <!-- /.box-header -->
                    <div class="box-body">
                        <table id="DataList" class="table table-bordered table-striped table-hover ">
                            <thead>
                                <tr>
                                    <th>编号</th>
                                    <th>名称</th>
                                    <th>标题</th>
                                    <th>图标</th>
                                    <th>选中图标</th>
                                    <th>排序</th>
                                    <th width="200px">简介</th>
                                    <th>添加时间</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody> </tbody>
                        </table>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->
@section JS{
    <script>

        $(function () {
            //初始化表格
            GenerateTable();
            //鼠标移动到该行变色
            $('.table-hover tbody').on('click', 'tr', function () {
                if ($(this).hasClass('selected')) {
                    $(this).removeClass('selected');
                    console.log();
                }
                else {
                    u_table.$('tr.selected').removeClass('selected');
                    $(this).addClass('selected');
                }
            });
            //搜索事件
            $("#btnSearch").on("click", function () {
                u_table.fnDestroy();
                GenerateTable();
            });
        });
        //生成表格
        function GenerateTable() {
            u_table = $('#DataList').dataTable({
                "lengthChange": true,
                "searching": false,
                "ordering": false,
                "iDisplayLength": 10,
                "bProcessing": true,
                "bServerSide": true,
                "fnServerParams": function (aoData) {
                    var classSelect = $("#classSelect").val();
                    var name = $("#name").val();
                    aoData.push(
                        { "name": "name", "value": name },
                        { "name": "status", "value": classSelect }
                    );
                },
                "sAjaxSource": "/systemsetting/UserRuleList",
                "aoColumns": [
                    { "mDataProp": 'id' },
                    {
                        "mDataProp": 'title', "mRender": function (data, type, full) {
                            return data + "<br/>" + (full.title_sub == null ? "" : full.title_sub);
                        }
                    },
                    { "mDataProp": 'subhead' },
                    {
                        "mDataProp": 'ico', "mRender": function (data, type, full) {
                            return data == null || data == '' ? "" : "<img style='max-height:35px;' src='" + domain + data + "' />"
                        }
                    },
                    {
                        "mDataProp": 'selected_ico', "mRender": function (data, type, full) {
                            return data == null || data == '' ? "" : "<img style='max-height:35px;' src='" + domain + data + "' />"
                        }
                    },
                    { "mDataProp": 'sort' },
                    { "mDataProp": 'summary' },
                    {
                        "mDataProp": 'add_time', "mRender": function (data, type, full) {
                            return moment(data).format("YYYY-MM-DD HH:mm:ss");
                        }
                    },
                    {
                        "mDataProp": 'status', "mRender": function (data, type, full) {
                            if (data == 1) {
                                return '<a style="text-decoration:none" class="btn btn-success" onClick="rule_noPass(this,' + full.id + ')" href="javascript:;" title="点击禁用">启用</a>';
                            } else {
                                return '<a style="text-decoration:none" class="btn btn-danger" onClick="rule_pass(this,' + full.id + ')" href="javascript:;" title="点击启用">禁用</a>';
                            }
                        }
                    },
                    {
                        "mDataProp": 'id', "mRender": function (data, type, full) {
                            return '<a class="btn btn-default " href = "/systemsetting/addUserRule/' + full.id + '"  title="编辑">编辑</a> ';
                        }
                    }
                ]
            });
        }

        /*启用*/
        function rule_pass(obj, id) {
            layer.confirm('确定启用？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/systemsetting/SetUserRuleIsUse",
                    dataType: "json",
                    data: { id: id, isUse: 1 },
                    success: function (data) {
                        if (data.status == "y") {
                            $(obj).text("启用").attr("onClick", "rule_noPass(this," + id + ")").attr("title", "点击启用").attr("class", "btn btn-success");
                            layer.msg('已启用', { icon: 6, time: 1000 });
                        }
                        else {
                            alert(data.info);
                        }
                    }
                });

            });
        }
        /*禁用*/
        function rule_noPass(obj, id) {
            layer.confirm('确定禁用？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/systemsetting/SetUserRuleIsUse",
                    dataType: "json",
                    data: { id: id, isUse: 0 },
                    success: function (data) {
                        if (data.status == "y") {
                            $(obj).text("禁用").attr("onClick", "rule_pass(this," + id + ")").attr("title", "点击启用").attr("class", "btn btn-danger");
                            layer.msg('已禁用', { icon: 5, time: 1000 });
                        }
                        else {
                            alert(data.info);
                        }
                    }
                });

            });
        }
    </script>
}


